package cn.pconline.autoclub.task;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

/**
 *
 * @author chensy
 */
public class FileUtils {

    private final static Properties properties = new Properties();
    public final static String confDir = "conf";
    private final static String fileName = "autoclub.properties";
    public final static String log4jName = "log4j.properties";

    static {
        try {
            properties.load(new BufferedInputStream(new FileInputStream(confDir + File.separator + fileName)));
        } catch (FileNotFoundException ex) {
            System.err.println("need config file:" + FileUtils.confDir + File.separator + FileUtils.fileName);
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }

    public static String getConfig(String key) {
        return properties.getProperty(key);
    }

    public static int getConfig(String key, int def) {
        String s = properties.getProperty(key);
        if (s == null || s.trim().length() == 0) {
            return def;
        }
        return Integer.parseInt(s);
    }

    public static boolean getConfig(String key, boolean def) {
        String s = properties.getProperty(key);
        if (s == null || s.trim().length() == 0) {
            return def;
        }
        return Boolean.valueOf(s);
    }

    private FileUtils() {
    }
}